package com.linux.huhx.batch;

import org.junit.Test;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.Resource;
import spring.batch.readFile.DecompressTasklet;

import java.io.File;
import java.io.IOException;


/**
 * @Author: huhx
 * @Date: 2017-09-14 上午 9:58
 * @Desc:
 */
public class JobLaunch {
    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("config/batch/batch.xml");
        JobLauncher launcher = (JobLauncher) context.getBean("jobLauncher");

        Job job = (Job) context.getBean("shareDataHolderJob");
        try {
            // 运行Job
            JobParametersBuilder parametersBuilder = new JobParametersBuilder();
            JobParameters jobParameters = parametersBuilder.
                    addString("status", "0").
                    toJobParameters();


            JobParameters test = new JobParameters();
            launcher.run(job, jobParameters);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

//    @Test
//    public void resourceTest() throws IOException{
//        ApplicationContext context = new ClassPathXmlApplicationContext("config/batch/batch.xml");
//        DecompressTasklet decompressTasklet = context.getBean("decompressTasklet", DecompressTasklet.class);
//        Resource resource = decompressTasklet.getInputResource();
//        System.out.println(resource.getFile().getAbsolutePath());
//
//        System.out.println(new File(decompressTasklet.getTargetDirectory(), decompressTasklet.getTargetFile()).getAbsolutePath());
//    }
}
